package com.example.demo.commons.core.util;

import cn.hutool.core.collection.CollectionUtil;
import com.google.common.collect.Lists;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.function.Function;

/**
 * <p> list 操作 </p>
 *
 * @author tanyunpeng
 * @date 2021/11/18
 */
public class LocalListUtils {

    public static <T, V> List<V> transferList(List<T> orgList, Function<T, V> function) {
        if (CollectionUtil.isEmpty(orgList)) {
            return Lists.newArrayList();
        }
        if (Objects.isNull(function)) {
            return Lists.newArrayList();
        }
        List<V> result = new ArrayList<>();
        orgList.forEach(t -> result.add(function.apply(t)));
        return result;
    }
}
